package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo6 {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException, ClassNotFoundException {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入类名:");
        String className = sc.nextLine();//此处打点
        Class cls = Class.forName(className);
        Method[] methods = cls.getDeclaredMethods();
        //  此处修改      复制使用 : reflect.Student
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i].getName());
        }
//        for (Method m:methods
//             ) {
//            System.out.println(m.getName());
//        }
        System.out.print("请输入方法名:");
        String methodName = sc.nextLine();

        Object o = cls.newInstance();
        Method method = cls.getDeclaredMethod(methodName);
        method.setAccessible(true);
        method.invoke(o);
        method.setAccessible(false);
    }
}
